<template lang="pug">
  el-dialog(
    title="选择移动到的位置"
    :visible="visibleDialog"
    width="480px"
    center
    @close="$_handleCancel"
    )
    org-select(
      :value="[]"
      :selectType="2"
      @valChange="val => this.orgIds = val"
    )
    p.tr(slot="footer")
      el-button(@click="$_handleCancel") 取消
      el-button(type="primary" @click="submitHandle" :loading="submitting") 确认
</template>
<script>
import OrgSelect from '@/components/Form/OrgSelect'
import { moveLoc } from '@/api/device'

export default {
  components: {
    OrgSelect
  },
  props: {
    id: {
      type: String,
      default: ''
    },
    visible: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    visibleDialog: {
      get () {
        return this.visible
      },
      set (val) {
        this.$emit('update:visible', val)
      }
    }
  },
  data () {
    return {
      submitting: false,
      orgIds: []
    }
  },
  methods: {
    submitHandle () {
      const { orgIds, id } = this
      if (!orgIds.length) {
        this.$message.error('请选择移动位置')
        return
      }
      this.submitting = true
      console.log(this.orgIds)
      moveLoc({ devId: id, medinsId: orgIds[0], deptId: orgIds[1] }).then(() => {
        this.$message.success('移动成功')
        this.$_handleCancel()
        this.$emit('getList')
      })
    },
    $_handleCancel () {
      this.visibleDialog = false
    }
  }
}
</script>
